import '../helper/dioHelper2.dart';

class FtpFile {
  int ID;
  String Guid;
  String UserId;
  String SpaceId;
  String FileName;
  String CreateTime;
  int State;
  int Size;
  String Remarks;

  FtpFile(this.ID, this.Guid, this.UserId, this.SpaceId, this.FileName,
      this.CreateTime, this.State, this.Size, this.Remarks);
  FtpFile.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        Guid = json["Guid"],
        UserId = json["UserId"],
        SpaceId = json["SpaceId"],
        FileName = json["FileName"],
        CreateTime = json["CreateTime"],
        State = json["State"],
        Size = json["Size"],
        Remarks = json["Remarks"];
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'Guid': Guid,
        'UserId': UserId,
        'SpaceId': SpaceId,
        'FileName': FileName,
        'CreateTime': CreateTime,
        'State': State,
        'Size': Size,
        'Remarks': Remarks,
      };
  static Future<bool> Add(FtpFile x1) async {
    var response = await DioHelper.Post("/FtpFile/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(FtpFile x1) async {
    var response = await DioHelper.Post("/FtpFile/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(FtpFile x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/FtpFile/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<FtpFile?> Get(String guid) async {
    var response = await DioHelper.Get("/FtpFile/Get?id=$guid", {});

    if (response.statusCode == 200)
      return new FtpFile.fromJson(response.data);
    return null;
  }

  static Future<List<FtpFile>> GetList(
      String id, int fType, int pageIndex, int pageSize) async {
    String p1 = pageIndex.toString();
    String ps = pageSize.toString();

    var response = await DioHelper.Get(
        "/FtpFile/GetList?SpaceId=$id&p1=$p1&ps=$ps", {});

    var list1 = <FtpFile>[];
    if (response.statusCode == 200) {
      if (response.data == null) return list1;
      for (var x in response.data) {
        list1.add(new FtpFile.fromJson(x));
      }
    }
    return list1;
  }

    static Future<List<FtpFile>> GetList2(
      String id,  int pageIndex, int pageSize) async {
    String p1 = pageIndex.toString();
    String ps = pageSize.toString();

    var response = await DioHelper.Get(
        "/FtpFile/GetList2?SpaceId=$id&p1=$p1&ps=$ps", {});

    var list1 = <FtpFile>[];
    if (response.statusCode == 200) {
      if (response.data == null) return list1;
      for (var x in response.data) {
        list1.add(new FtpFile.fromJson(x));
      }
    }
    return list1;
  }

  static Future<List<FtpFile>> GetAllList() async {
    var response = await DioHelper.Get("/FtpFile/GetAllList", {});
    var list1 = <FtpFile>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new FtpFile.fromJson(x));
      }
    }
    return list1;
  }
}
